<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="_header_include::frag(~{::title},~{::style},~{})">
    <title>后台管理系统</title>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/element-ui.css">
    <link rel="stylesheet" href="css/base.css">
    <style>
        .dialogForm .el-form-item{margin-bottom: 5px;}
        .mainSearchBg .el-form-item__label{width:auto;}
    </style>
</head>
<body>

<div id="optimizeClueManagement" class="optimizeClueManagement mainPadding" style="display: none;">
    <el-breadcrumb separator="/" class="elBreadcrumb marginB20">
        <el-breadcrumb-item>Home</el-breadcrumb-item>
        <el-breadcrumb-item>商务管理</el-breadcrumb-item>
        <el-breadcrumb-item>更改付款记录</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row class="marginB20">
         <shiro:hasPermission name="paydetail:payChangRecord:export">
            <el-button type="primary" @click="exportFun"><i ></i>导出</el-button>
         </shiro:hasPermission>
    </el-row>
    <div class="mainSearchBg">
        <div class="mainSearchFormBox">
            <el-form :inline="true" class="demo-form-inline mainSearchForm" :model="form" ref="form"> 
                <el-form-item label="签约单编号:">
                    <el-input v-model="form.signNo" placeholder="签约单编号"></el-input>
                </el-form-item>
                <el-form-item label="商务组:">
                    <el-select v-model="form.busGroupId" placeholder="商务组" style="width: 100%;" clearable filterable @change="currentTelSale">
                        <el-option
                                v-for="item in businessGroupList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="商务经理:">
                    <el-select v-model="form.businessManagerId" placeholder="商务经理" style="width: 100%;" clearable filterable>
                        <el-option
                                v-for="item in busManagerList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="变更时间:">
                    <el-date-picker
                            v-model="form.startTime"
                            type="datetime"
                            placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="—" class="widthauto">
                    <el-date-picker
                            v-model="form.endTime"
                            type="datetime"
                            placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="">
                    <el-button icon="el-icon-search" type="primary" @click="searchTable('form')"  class="searchBtn" style="margin-left: 10px;">搜索</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-row>
            <el-table
                ref="multipleTable"
                tooltip-effect="dark"
                style="width: 100%"
                border
                :data="dataTable"
                v-loading="loading" 
                @selection-change="handleSelectionChange">
                <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                <el-table-column align="center" type="index" label="序号"  width="55"></el-table-column>
                <el-table-column align="center" prop="createTime" label="变更时间" width="130"></el-table-column>
                <el-table-column align="center" prop="signNo" label="签约单编号"  width="150"></el-table-column>
                <el-table-column align="center" prop="payTypeName" label="付款类型" width="130"></el-table-column>
                <el-table-column align="center" prop="statementNo" label="结算单编号"  width="150"></el-table-column>
                <el-table-column align="center" prop="businessManagerName" label="商务经理"  width="120"></el-table-column>
                <el-table-column align="center" prop="businessGroupName" label="商务组"  width="120"></el-table-column>
                <el-table-column align="center" prop="createUserName" label="变更人"  width="120"></el-table-column>
                <el-table-column align="center" prop="operationTypeName" label="操作类型"  width="120"></el-table-column>
                <el-table-column align="center" prop="remark" label="备注"></el-table-column>
            </el-table>
            <table-pagination :pager="pager" @change="searchTable"></table-pagination>
        </el-row>
    </div>
    
</div>
</body>
<!-- import Vue before Element -->
<div th:include="_footer_include :: #jsLib"></div>

<!-- import common js-->
<script th:inline="javascript">
    var ocmVM = new Vue({
        el: '#optimizeClueManagement',
        data: function() {
            return {
                loading: false,
                isDisabled: false,
                isDisabledOrgId: false,
                multipleSelection: [],//选择行
                pager:{
                  total: 0,
                  currentPage: 1,
                  pageSize: 20,
                },
                form: {
                    signNo:'',
                    busGroupId:'',
                    businessManagerId:'',
                    startTime:'',
                    endTime:'',
                },
                formLabelWidth: '120px',
                dataTable: [],
                businessGroupList:[],
                busManagerList: [],
               
            }        	  
        },
        methods: {
            clickRow(row){
                this.$refs.multipleTable.toggleRowSelection(row)
            },
            handleSelectionChange(val) {//选择节点的事件
                // console.log(val)
                this.multipleSelection = val;
            },
            handleStart(index, row) {
                console.log(index, row);
            },
            handleForbid(index, row) {
                console.log(index, row);
            },            
            searchTable() {                
                var startTime= this.form.startTime;              
                var endTime= this.form.endTime;
                var assignName= this.form.assignName;
                if(endTime){
                  if(endTime<startTime){
                      this.$message({
                          type: 'warning',
                          message: '结束时间不能早于开始时间'
                      });
                      return ;
                  } 
                }  
                var param =this.form;
                param.pageSize = this.pager.pageSize;
                param.pageNum = this.pager.currentPage; 
                axios.post('/payChangRecord/getPageList', param)
                .then(function (response) {
                    console.log(response)
                    var result =  response.data;
                    console.info(result);
                    if(result.code=="0"){
                        var table=result.data;
                        ocmVM.dataTable= table.data;
                        ocmVM.pager.total =  table.total;
                        ocmVM.pager.currentPage = table.currentPage;
                    }else{
                        ocmVM.$message.error(result.msg);
                    }  
                })
                .catch(function (error) {
                     console.log(error);
                });
                
            },
            exportFun(){
                var param = this.form;
                param.pageNum='';
                param.pageSize='';
                axios.post('/payChangRecord/exportPayChangRecord',param,{responseType:'blob'})
                .then(function (response) {
                    console.log(response)
                    var data =  response.data;
                    var fileName = response.headers.filename;
                    saveAs(data,decodeURI(fileName));
                })
                .catch(function (error) {
                    console.log(error);
                }).then(function(){
                	ocmVM.loading=false;
                });                     	
            	
            },
          //日期数据格式化方法
            dateFormat( row, column, cellValue, index) {
              if (cellValue == undefined) {
                 return "";
              }
              return moment(cellValue).format("YYYY-MM-DD HH:mm:ss");
        //       return moment(cellValue).format("YYYY-MM");
            },
            queryBusGroupList() {//根据组织机构Id查询所有商务经理
                axios.post('/organization/organization/queryBusGroupList', {})
                    .then(function (response) {
                        var result = response.data;
                        if (result.code == '0') {
                            var table = result.data;
                            ocmVM.businessGroupList = table;
                        } else {
                            console.error(response);
                        }

                    })
                    .catch(function (error) {
                        console.log(error);
                    });

            },
            currentTelSale(seleVal){
                if(seleVal==null||seleVal==""){
                    return ;
                }
                this.getTelSale(seleVal);
            },
            getTelSale(seleVal){
                param={};
                param.orgId=seleVal;
                param.roleCode="SWJL"; 
                axios.post('/base/getSaleList' ,param).then(function (response) {
                    ocmVM.busManagerList=response.data.data;
                }).catch(function (error) {
                        ocmVM.$message({
                        message: "商务经理请求失败，请稍后重试",
                        type: "error"
                    });
                });
            },
            queryBusManagerByOrgId() {//获取所有商务经理
                axios.post('/sign/signRecord/queryBusManagerByOrgId', {})
                    .then(function (response) {
                        var result = response.data;
                        if (result.code == '0') {
                            var table = result.data;
                            ocmVM.busManagerList = table;
                        } else {
                            console.error(response);
                        }

                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },
            initSelect() {//初始下拉框
                this.queryBusManagerByOrgId();
            },
        },
        created(){
            var localVal=localStorage.getItem('allChangePageSize')?parseInt(localStorage.getItem('allChangePageSize')):'';
            if(localVal){this.pager.pageSize = localVal;}
            // console.info("create method");
            this.queryBusGroupList();
            this.searchTable();
        },
        mounted(){
            document.getElementById('optimizeClueManagement').style.display = 'block';
        }
  })
</script>
</html>